<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>canvas动画</title>
    <style>
        /*不能在里面设置宽高*/
        canvas {
            border: 1px solid black;
        }
    </style>
</head>
<body>
<button id="bt">动画</button>
<br>
<br>

</body>

<script>


    const canvas = document.createElement('canvas');
    document.body.append(canvas)
    const ctx = canvas.getContext('2d');
    let width = 600;
    let height = 600;
    canvas.width = width
    canvas.height = height


    let x = 0;
    const animation=()=>{
        ctx.beginPath();
        ctx.clearRect(0, 0, 600, 600);
        ctx.fillRect(x++, 0, 100, 100);
        ctx.closePath();
        requestAnimationFrame(animation);
    }
    const generateGround = () => {
        requestAnimationFrame(animation)

    }

    const button = document.getElementById('bt');
    button.addEventListener('click', generateGround);


    const deg2Arc = (deg) => {
        return (deg * Math.PI) / 180;
    }

</script>
</html>